package br.ufal.ic.user;

import br.ufal.ic.core.CubistInformation;
import java.io.Serializable;
import javax.persistence.*;

/**
 *
 * @author Marcos Paulo
 */
@Entity(name = "users")
public class User implements Serializable {

    @Id
    private String nickName;
    private String password;
    @OneToOne(cascade = javax.persistence.CascadeType.ALL)
//    @Cascade(CascadeType.SAVE_UPDATE)
    private CubistInformation information;

    protected User() {
        //for hibernate
    }

    public User(String nickName, String password, CubistInformation information) {

        if (nickName == null || nickName.equalsIgnoreCase("")) {
            throw new IllegalArgumentException("nickName não pode ser null");
        }

        if (password == null || password.equalsIgnoreCase("")) {
            throw new IllegalArgumentException("password não pode ser null");
        }

        if (information == null) {
            throw new IllegalArgumentException("information não pode ser null");
        }
        this.nickName = nickName;
        this.password = password;
        this.information = information;
    }

    public String getNickName() {
        return nickName;
    }

    public String getPassword() {
        return password;
    }

    public CubistInformation getInformation() {
        return information;
    }

    //TODO procurar melhor forma de se comporar usarios
    @Override
    public boolean equals(Object obj) {
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        User other = (User) obj;
        return this.nickName.equals(other.nickName);
    }

    @Override
    public int hashCode() {
        return 97 * 7 + nickName.hashCode();
    }

    @Override
    public String toString() {
        return "User{" + "nickName=" + nickName + "password=" + password + '}';
    }
}
